package com.yz.core.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @className: HttpUtils
 * @author: shuishui
 * @date: 2023/01/12 18:53
 */
@Component
public class HttpUtils {
    @Autowired
    private RestTemplate restTemplate;
    public ResponseEntity post(String url, Object data) {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity httpEntity = new HttpEntity(data, httpHeaders);
        ResponseEntity responseEntity = restTemplate.postForEntity(url,httpEntity, Object.class);
        return responseEntity;
    }
    public ResponseEntity get(String url) {
        return restTemplate.getForEntity(url, Object.class);
    }
}
